package com.bestow.lease.controller;

import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.bestow.common.annotation.Log;
import com.bestow.common.core.controller.BaseController;
import com.bestow.common.core.domain.AjaxResult;
import com.bestow.common.enums.BusinessType;
import com.bestow.lease.domain.PrjPlan;
import com.bestow.lease.service.IPrjPlanService;
import com.bestow.common.utils.poi.ExcelUtil;
import com.bestow.common.core.page.TableDataInfo;

/**
 * 项目方案维护Controller
 *
 * @author liliu
 * @date 2022-12-07
 */
@RestController
@RequestMapping("/lease/plan" )
public class PrjPlanController extends BaseController {
    @Autowired
    private IPrjPlanService prjPlanService;

    /**
     * 查询项目方案维护列表
     */
    @PreAuthorize("@ss.hasPermi('lease:plan:list')" )
    @GetMapping("/list" )
    public TableDataInfo list(PrjPlan prjPlan) {
        startPage();
        List<PrjPlan> list = prjPlanService.selectPrjPlanList(prjPlan);
        return getDataTable(list);
    }

    /**
     * 导出项目方案维护列表
     */
    @PreAuthorize("@ss.hasPermi('lease:plan:export')" )
    @Log(title = "项目方案维护" , businessType = BusinessType.EXPORT)
    @PostMapping("/export" )
    public void export(HttpServletResponse response, PrjPlan prjPlan) {
        List<PrjPlan> list = prjPlanService.selectPrjPlanList(prjPlan);
        ExcelUtil<PrjPlan> util = new ExcelUtil<PrjPlan>(PrjPlan.class);
        util.exportExcel(response, list, "项目方案维护数据" );
    }

    /**
     * 获取项目方案维护详细信息
     */
    @PreAuthorize("@ss.hasPermi('lease:plan:query')" )
    @GetMapping(value = "/{planId}" )
    public AjaxResult getInfo(@PathVariable("planId" ) Long planId) {
        return AjaxResult.success(prjPlanService.selectPrjPlanByPlanId(planId));
    }

    /**
     * 新增项目方案维护
     */
    @PreAuthorize("@ss.hasPermi('lease:plan:add')" )
    @Log(title = "项目方案维护" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PrjPlan prjPlan) {
        return toAjax(prjPlanService.insertPrjPlan(prjPlan));
    }

    /**
     * 修改项目方案维护
     */
    @PreAuthorize("@ss.hasPermi('lease:plan:edit')" )
    @Log(title = "项目方案维护" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PrjPlan prjPlan) {
        return toAjax(prjPlanService.updatePrjPlan(prjPlan));
    }

    /**
     * 删除项目方案维护
     */
    @PreAuthorize("@ss.hasPermi('lease:plan:remove')" )
    @Log(title = "项目方案维护" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{planIds}" )
    public AjaxResult remove(@PathVariable Long[] planIds) {
        return toAjax(prjPlanService.deletePrjPlanByPlanIds(planIds));
    }

    /**
     * 生成项目方案excel
     */
    @PreAuthorize("@ss.hasPermi('lease:plan:excelcreate')" )
    @PostMapping("/excelcreate" )
    public AjaxResult excelCreate(HttpServletRequest request) {
        Long planId = Long.valueOf(request.getParameter("plan_id"));
        return toAjax(prjPlanService.prjPlanCreatExcel(planId));
    }
}
